package com.achao.exception;

import com.achao.javabeans.dto.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常捕获
 *
 * @Author: achao
 * @DateTime: 2022/8/18 11:42
 * @Description: TODO
 */

@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    public void doException(Exception e) {
        System.out.println("异常..嘿嘿,异常..嘿嘿嘿");
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(value = RuntimeException.class)
    public Result exception(RuntimeException e) {

        System.out.println("系统运行时异常--->{}" + e.getMessage());
        return Result.fail(e.getMessage());
    }

}
